/**
 * Created by kevin on 16/8/16.
 */
var eosi = window.eosi || {};
this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = function(name) {
//    this.name = name;
//};

(function (window) {
    // the application
    function Fotilewait_play(master) {
        this.Container_constructor();
        this.version = master.version;
        this.init(master);
    }
    var p = createjs.extend(Fotilewait_play, createjs.Container);

    // public methods:
    p.init = function (master) {
        this.fotile = master;
        console.log("I'm Master wait!!!");
        this.loadFirsrMaster();
    }

    //UI
    p.setupUI = function (){


    }

    //加载wait
    p.loadFirsrMaster = function (){
        var wait = this;
        var load=[
            {src:"static/master/wait/bg1.jpg",id:"bg"},
            {src:"static/master/wait/bottom_2.png",id:"bottom_1"},
            {src:"static/master/wait/logo_suc.png",id:"logo_suc2"},
            {src:"static/master/wait/phone_center.png",id:"phone_center"},]
        Fotileloader = new eosi.fotile.Fotileloader(this.fotile,load,function(){
            wait.setupLoaderUI();
        },1);
        container.addChild(Fotileloader);

        p.setupLoaderUI = function (){
            _this=this;
            var bg = new createjs.Bitmap(this.fotile.master_UILoader.getResult("bg"));
            var bottom_1 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("bottom_1"));
            var logo_suc2 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("logo_suc2"));
            var phone_center = new createjs.Bitmap(this.fotile.master_UILoader.getResult("phone_center"));
            var play = new createjs.Bitmap(this.fotile.master_UILoader.getResult("play"));
            var massage = new createjs.Text("请把你的手机放在右边\n进行观看", "2.4vh Arial", "#000000");

            var v_w = bg.getBounds().width;
            var v_h = bg.getBounds().height;
            var w = this.fotile.getWidth();
            var h = this.fotile.getHeight();
            var ratio_y = h/v_h;
            var ratio_x =  w/v_w;
            bg.setTransform(0,0,ratio_x,ratio_y);
            bg.x=0;
            bg.y=0;

            bottom_1.setTransform(0,0,ratio_x*1.14,ratio_x*1.14);
            bottom_1.x = (this.fotile.getWidth())-(bottom_1.getBounds().width*ratio_x*1.14);
            bottom_1.y = (this.fotile.getHeight())-(bottom_1.getBounds().height*ratio_x*1.14);
            bottom_1.alpha = 1;

            logo_suc2.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            logo_suc2.x =this.fotile.getWidth()/2-logo_suc2.getBounds().width*ratio_x*1.1/2;
            logo_suc2.y = (this.fotile.getHeight()*0.3)-(logo_suc2.getBounds().height*ratio_x*1.1/2);
            logo_suc2.alpha = 1;


            phone_center.setTransform(0,0,ratio_x,ratio_x);
            phone_center.x = this.fotile.getWidth()/2-phone_center.getBounds().width*ratio_x/2;
            phone_center.y = (this.fotile.getHeight()*0.25)+(phone_center.getBounds().height/2*ratio_x)*2;

            massage.lineHeight = 22;
            massage.textBaseline = "top";
            massage.textAlign = "center";
            // massage.x = this.fotile.getWidth()/2-massage.getBounds().width/2;
            massage.x =this.fotile.getWidth()/2;
            massage.y = (this.fotile.getHeight()*0.6)+(massage.getBounds().height/2);


            this.addChild(bg);
            this.addChild(bottom_1);
            this.addChild(logo_suc2);
            this.addChild(phone_center);
            this.addChild(play);
            this.addChild(massage);
            stage.update();
            // this.clearLoading=function (){
            //     this.removeChild(bg);
            //     this.removeChild(text_box_bg);
            //     this.removeChild(logo);
            //     this.removeChild(a_1);
            //     this.removeChild(a_2);
            //     this.removeChild(a_3);
            //     this.removeChild(a_4);
            //     this.removeChild(a_5);
            //     this.removeChild(a_6);
            //     this.removeChild(bn);
            //     this.removeChild(downarrow);

            //     document.getElementById("canvas").removeEventListener("click",clickPlayBn);
            //     container.removeChild(master);
            //     stage.update();
            // }

        }

    }
    // add MyApp to myNameSpace
    window.eosi.fotile.Fotilewait_play = createjs.promote(Fotilewait_play, "Container");
}(window));
